//
//  CardsListViewController.m
//  WBBaseProject
//
//  Created by xiaozhi on 2018/3/23.
//  Copyright © 2018年 吴斌. All rights reserved.
//

#import "CardsListViewController.h"
#import "CardsChildTableViewController.h"


@interface CardsListViewController ()

@property (nonatomic, strong) UIView *redView;
@property (nonatomic, strong) UIView *lineView;
@end

#define BOTTOM 80

@implementation CardsListViewController

- (UIView *)redView {
    if (!_redView) {
        _redView = [[UIView alloc] initWithFrame:CGRectZero];
        _redView.backgroundColor = [UIColor colorWithRed:168.0/255.0 green:20.0/255.0 blue:4/255.0 alpha:1];
    }
    return _redView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    if (self.menuViewStyle == WMMenuViewStyleTriangle) {
        [self.view addSubview:self.redView];
    }
    
    self.title = @"优惠券";
    [self addLeftBtn];
    
    self.menuItemWidth = 80;
    
    [self lineView];
    
    [self addInvalidBtn];
}
- (void)addInvalidBtn
{
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, kScreenHeight-BOTTOM-64, kScreenWidth, BOTTOM)];
    [btn setTitle:@"查看已失效的券" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(showInvalid:) forControlEvents:UIControlEventTouchUpInside];
    
    btn.contentMode = UIViewContentModeCenter;
    
    [self.view addSubview:btn];
}
- (void)showInvalid:(UIButton*)btn
{
    
}
- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 43, kScreenWidth, 1)];
        _lineView.backgroundColor = [UIColor colorWithRed:177.0/255.0 green:177.0/255.0 blue:177/255.0 alpha:1];
        
        [self.menuView insertSubview:_lineView belowSubview:self.menuView.progressView];
        
    }
    return _lineView;
}
- (void)addLeftBtn{
    //返回按钮
    UIButton *btn = [Factory backButton:self];
    [btn addTarget:self action:@selector(clickBack:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *right = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
    right.titleLabel.font = WB_FontSize(15);
    [right setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [right setTitle:@"添加" forState:UIControlStateNormal];
    [right addTarget:self action:@selector(toAdd) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:right];
    self.navigationItem.rightBarButtonItem = item;
}
- (void)clickBack:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)toAdd
{
    
}
- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    self.redView.frame = CGRectMake(0, CGRectGetMaxY(self.menuView.frame), self.view.frame.size.width, 2.0);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    return 2;
}

- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
    switch (index) {
        case 0: return @"加息券(2)";
        case 1: return @"抵用券(3)";
        
    }
    return @"NONE";
}

- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    switch (index) {
        case 0: return [[CardsChildTableViewController alloc] init];
        case 1: return [[CardsChildTableViewController alloc] init];
    }
    return [[UIViewController alloc] init];
}

- (CGFloat)menuView:(WMMenuView *)menu widthForItemAtIndex:(NSInteger)index {
    CGFloat width = [super menuView:menu widthForItemAtIndex:index];
    return width + 20;
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForMenuView:(WMMenuView *)menuView {
//    if (self.menuViewPosition == WMMenuViewPositionBottom) {
//        menuView.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1.0];
//        return CGRectMake(0, self.view.frame.size.height - 44, self.view.frame.size.width, 44);
//    }
    CGFloat leftMargin = self.showOnNavigationBar ? 50 : 0;
    CGFloat originY = self.showOnNavigationBar ? 0 : CGRectGetMaxY(self.navigationController.navigationBar.frame);
    originY = 25;
    return CGRectMake(leftMargin, originY, self.view.frame.size.width - 2*leftMargin, 44);
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForContentView:(WMScrollView *)contentView {
//    if (self.menuViewPosition == WMMenuViewPositionBottom) {
//        return CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 64 - 44);
//    }
    CGFloat originY = CGRectGetMaxY([self pageController:pageController preferredFrameForMenuView:self.menuView]);
    if (self.menuViewStyle == WMMenuViewStyleTriangle) {
        originY += self.redView.frame.size.height;
    }
    return CGRectMake(0, originY, self.view.frame.size.width, self.view.frame.size.height - originY-BOTTOM);
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
